' DOC: D3DUtil_SetupDefaultScene setup a camera lights and materials
' DOC: D3DUtil_SetupCamera point camera
' DOC: D3DUtil_SetupMediaPath set directory to load textures from
' DOC: D3DUtil_PresentAll show graphic on the screen
' DOC: D3DUtil_ResizeWindowed resize for windowed modes
' DOC: D3DUtil_ResizeFullscreen resize to fullscreen mode
' DOC: D3DUtil_CreateTextureInPool create a texture
Option Explicit
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef RECT As RECT) As Long
Private Declare Function GetClientRect Lib "user32.dll" (ByVal hwnd As Long, ByRef RECT As RECT) As Long
Private Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long, ByVal hwndafter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal options As Long) As Long
Private Declare Function SetWindowLongA Lib "user32.dll" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal newVal As Long) As Long
Private Declare Function GetWindowLongA Lib "user32.dll" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Function D3DUtil_Init(hwnd As Long, bWindowed As Boolean, AdapterIndex As Long, modeIndex As Long, devtype As CONST_D3DDEVTYPE, CallbackObject As Object) As Boolean
On Local Error GoTo errOut
' Initialize the DirectX8 and d3dx8 objects
If g_dx Is Nothing Then Set g_dx = New DirectX8
If g_d3dx Is Nothing Then Set g_d3dx = New D3DX8
' Create the Direct3D object
Set g_d3d = g_dx.Direct3DCreate
' Call the sub that builds a list of available adapters,
Function D3DUtil_InitFullscreen(hwnd As Long, AdapterIndex As Long, modeIndex As Long, devtype As CONST_D3DDEVTYPE, bTryFallbacks As Boolean) As Boolean
On Error GoTo errOut
Dim ModeInfo As D3DUTIL_MODEINFO
Dim rc As RECT
'save the current adapter
g_lCurrentAdapter = AdapterIndex
g_focushwnd = hwnd
'switching from windowed to fullscreen so save height and width
If g_d3dpp.Windowed = 1 Then
Call GetClientRect(g_focushwnd, rc)
g_lWindowWidth = rc.Right - rc.Left
g_lWindowHeight = rc.bottom - rc.Top
Call GetWindowRect(g_focushwnd, g_WindowRect)
End If
' Initialize the present parameters structure
' to use 1 back buffer and a 16 bit depth buffer
' change the autoDepthStencilFormat if you need stencil bits
Private Function D3DEnum_CheckFormatCompatibility(lAdapter As Long, DeviceType As CONST_D3DDEVTYPE, format As CONST_D3DFORMAT, ByRef OutCanDoWindowed As Boolean, ByRef OutCanDoFullscreen As Boolean) As Long
On Local Error GoTo errOut
D3DEnum_CheckFormatCompatibility = -1
Dim d3dcaps As D3DCAPS8
Dim flags As Long
' Filter out incompatible backbuffers
' Note: framework always has the backbuffer and the frontbuffer (screen) format matching